<html>
<#include "../common/header.ftl" />

<!--引入jquery和wangEditor.js-->
<!--注意：javascript必须放在body最后，否则可能会出现问题-->
<link rel="stylesheet" type="text/css"
	href="static/dist/css/wangEditor.min.css">
<link rel="stylesheet" type="text/css" href="static/css/select.css">
<script type="text/javascript" src="static/dist/js/wangEditor.min.js"></script>
<script type="text/javascript" src="static/js/select.js"></script>
</head>
<script type="text/javascript">
	$(function() {
		$('#subBtn').on('click', function() {
			if (($("#ip1").val().trim()) == '') {
				tip('标题不可为空');
				return;
			}
			if (($("#textarea1").val().trim()) == '') {
				tip('内容不可为空！');
				return;
			}
			let obj = {};
			obj.title = $("#ip1").val().trim();
			obj.type = parseInt($("#ip2").val().trim());
			obj.content = $("#textarea1").val().trim();
			obj.img = $("#ip3").val().trim();
			console.log(JSON.parse(JSON.stringify(obj)))
			$.ajax({
				url : "indexnews?method=<#if info ??>edit&id=${info.id}<#else>add</#if>",
				type : "POST",
				data : JSON.stringify(obj),
				scriptCharset : 'utf-8',
				contentType : "application/json; charset=utf-8",
				success : function(res) {
					console.log(JSON.parse(res))
					let data = JSON.parse(res)
					if (data.code === 0) {
						tip(data.msg)
						<#if info ??>
						setTimeout(" location.reload()",  700)
						<#else>
						setTimeout(" location.reload()",  700)
						</#if>
						
					} else {
						tip(data.msg)
					}
				},
				error : function(res) {
					console.log("res", res);
				}
			});
			/* console.log('data', $('form').serializeArray()) */
		})
	});
	function tip(msg) {
		$("#warn").text(msg)
		$("#modal-282051").click()
	}
	function del(id){
		$.ajax({
			url : "indexnews?method=delete&id="+id,
			type : "GET",
			success : function(res) {
				let data = JSON.parse(res)
				if (data.code === 0) {
					tip(data.msg)
					setTimeout(" location.reload()",  700)
					}
				else{
					tip(data.msg)
				}
			}
		})
	}
	function delNewsItem(id){
		$.ajax({
			url : "indexnews?method=deleteNewsItem&id="+id,
			type : "GET",
			success : function(res) {
				let data = JSON.parse(res)
				if (data.code === 0) {
					tip(data.msg)
					setTimeout(" location.reload()",  700)
					}
				else{
					tip(data.msg)
				}
			}
		})
	}
</script>
<#if Session.user ?? && user.role==1>
<body style="margin-left: 200px">

	<div id="wrapper" class="toggled"><#--边栏sidebar--> <#include
		"../common/nav.ftl" /> <#--主要内容content--></div>
	<#else>
<body>
	</#if>
	<div class="container">

		<div class="row clearfix">

			<div class="col-md-12 column">

				<#include "../modal/tips.ftl"/> <a
					id="modal-282051" href="#modal-warns" style="display: none"
					role="button" class="" data-toggle="modal"></a>
				<div class="jumbotron"
					style="background-image: url(static/image/logo.jpeg); height: 380px; background-size: 100%; color: white">
					<h1>新闻管理</h1>
				</div>
				<#if types ??>
				<button class="btn btn-warning" type="button">
					<em class="glyphicon glyphicon-align-left"></em> 模块：
				</button>

				<#list types as item> <a
					href="indexnews?method=type&key=${item.type }&doer=list"><button
						class="btn btn-info" type="button">${item.name }</button></a> </#list>
						<#if list ??><#else>
						<br/><br/>
						<div class="alert alert-success alert-dismissable" >
					<button type="button" class="close" data-dismiss="alert"
						aria-hidden="true">×</button>
					<h4>
						<b>点击对应模块模块，对其进行操作</b>
					</h4>
				</div>
						</#if>
				</#if>
				<hr />
				<#if type ??>
				<div class="alert alert-success alert-dismissable">
					<button type="button" class="close" data-dismiss="alert"
						aria-hidden="true">×</button>
					<h4>
						<b>当前模块位置：<label>${type.name}</label></b>
					</h4>
				</div>
				</#if> 
				
				<#if list ??>

				<div class="row clearfix">
					<#list list as item>
					<div class="col-sm-4 col-md-3 col-xs-6 column">
						<div class="panel panel-primary">
							<div class="panel-heading">
								<blockquote>${item.title}
									<br /> <br />
									<div style="display: block-inline">
										<a class="btn btn-warning"
											href="indexnews?method=type&key=<#if type ??>${type.type}</#if>&doer=list&id=${item.id}">修改</a>
										<a class="btn btn-warning" href="#" onclick="del(${item.id})"
											style="float: right">删除</a>
									</div>


								</blockquote>
							</div>
							<div class="panel-footer">${item.content}</div>
						</div>
					</div>
					</#list>
				</div>
				<hr />
				<#if lists ??> 
				<div class="alert alert-success alert-dismissable" >
					<button type="button" class="close" data-dismiss="alert"
						aria-hidden="true">×</button>
					<h4>
						<b>当前模块新闻：</b>
					</h4>
				</div>
				</hr>
				<#list lists.data as item> 
					
					<a
						target="_blank"
						href="index?method=detail_page&id=${item.id }"
						class="list-group-item 
						<#if item.state == 0>	list-group-item-success</#if>
						<#if item.state == 1> list-group-item-danger</#if>
						"
						>
						<h4 class="list-group-item-heading">
						
						<div>
							${item.title }
							_By【Admin】 
							</div>
						</h4>
						创建时间：<span class="label label-primary">${item.createtime } </span>
						 修改时间：<span class="label label-primary">${item.updatetime } </span>
							
					</a> 
					<a class="btn btn-warning" href="indexnews?method=edit_page&id=${item.id }">修改</a>
					<a class="btn btn-danger" href="#" onclick="delNewsItem(${item.id })">删除</a>
					<hr/>
					
					 </#list>
				</#if>
					<div class="col-md-12 column">
				<ul class="pagination pull-right">
					<#if lists.pageNo lte 1>
					<li class="disabled"><a href="#">上一页</a></li> <#else >
					<li><a
					<#if type ?? && type == "news_click" >
						href="index?method=sort&page=${lists.pageNo - 1}&size=${lists.pageSize}&key=news_click"
					<#elseif type ?? && type == "news_id" >
						href="index?method=sort&page=${lists.pageNo - 1}&size=${lists.pageSize}&key=news_id"
					<#elseif newsType ?? >
						href="index?method=list&page=${lists.pageNo - 1}&size=${lists.pageSize}&type=${newsType }"
					<#else>
						href="index?method=list&page=${lists.pageNo - 1}&size=${lists.pageSize}"
					</#if>						
						>上一页</a>
					</li> </#if> <#list 1..lists.totalPage as index> <#if lists.pageNo ==
					index>
					<li class="disabled"><a href="#">${index}</a></li> <#else>
					<li><a
						<#if type ?? && type == "news_click" >
						href="index?method=sort&page=${index}&size=${lists.pageSize}&key=news_click"
					<#elseif type ?? && type == "news_id" >
						href="index?method=sort&page=${index}&size=${lists.pageSize}&key=news_id"
					<#elseif newsType ?? >
						href="index?method=list&page=${index}&size=${lists.pageSize}&type=${newsType }"
					<#else>
						href="index?method=list&page=${index}&size=${lists.pageSize}"	
					</#if>
						>${index}</a>
					</li> </#if> </#list> <#if lists.pageNo gte lists.totalPage>
					<li class="disabled"><a href="#">下一页</a></li> <#else >
					<li><a
					<#if type ?? && type == "news_click" >
						href="index?method=sort&page=${lists.pageNo + 1}&size=${lists.pageSize}&key=news_click"
					<#elseif type ?? && type == "news_id" >
						href="index?method=sort&page=${lists.pageNo + 1}&size=${lists.pageSize}&key=news_id"
					<#elseif newsType ?? >
						href="index?method=list&page=${lists.pageNo + 1}&size=${lists.pageSize}&type=${newsType }"
					<#else>
						href="index?method=list&page=${lists.pageNo + 1}&size=${lists.pageSize}"	
					</#if>
						>下一页</a>
					</li> </#if>
				</ul>
			</div>
				</#if>
				<br/>
			<hr/>
			
				 <#if type ?? >

				<div
				style="margin-top:10px"
					class="alert 
						<#if info ??>alert-warning <#else>alert-success </#if>
						alert-dismissable">
					<button type="button" class="close" data-dismiss="alert"
						aria-hidden="true">×</button>
					<h3><#if info ??>修改模块信息<#else>添加模块至${type.name}</#if></h3>
				</div>
				<form class="container"
					style="width: 90%; margin: 0 auto; max-width: 1380px" role="form">

					<div class="form-group">
						<label>模块名称</label> <input id="ip1" class="form-control"
							placeholder="请输入..." type="text"<#if info
						??>value="${info.title}" </#if> />
					</div>
					<input id="ip2" type="hidden" value="${type.type}" />
					<div class="form-group">
						<label>模块图片</label> <input id="ip3" class="form-control"
							placeholder="请输入...url" type="text" name="img"<#if info
						??><#if info.img ??>value="${info.img}" </#if></#if> />
					</div>

					<div class="form-group">
						<label>模块内容</label>
						<textarea name="newsContent" id="textarea1" style="height: 500px"
							placeholder="请输入..."><#if info ??>  ${info.content }</#if></textarea>
						<script type="text/javascript">
							var editor = new wangEditor('textarea1');
							editor.create();
						</script>

					</div>
					<input id="ip3" type="hidden"
						value='<#if Session.user ??> ${Session.user.id } </#if>' />
					<button id="subBtn" type="button"
						class="btn btn-<#if info ??>warning<#else>primary </#if>
					">
						<#if info ??>修改 <#else>添加 </#if></button>
				</form>
				</#if>
			</div>
			<script src="static/js/3.1.0bootstrap.min.js"></script>
</body>
</html>

